package com.hoas.comparedb.pojo;

import com.hoas.comparedb.entity.Table;
import com.hoas.comparedb.util.StrTool;

public class TableDiffItem extends DiffItem<Table> {

    public static final String NO = "NO";
    public static final String CREATE = "CREATE";
    public static final String ALTER = "ALTER";
    public static final String DROP = "DROP";

    public TableDiffItem(Table ot, Table nt) {
        super(ot, nt);
        if (nt != null) {
            setKey( nt.getTableSchema() + "." + nt.getTableName());
        } else {
            setKey( ot.getTableSchema() + "." + ot.getTableName());
        }

        if (ot == null && nt != null) {
            setType( CREATE );
        } else if( ot != null && nt != null) {
            setType( ALTER );

            if (
                    StrTool.equals(ot.getTableComment(), nt.getTableComment())
                            && StrTool.equals(ot.getTableCollation(), nt.getTableCollation())
            ) {
                setType( NO );
            }

        } else if(ot != null && nt == null) {
            setType(DROP);
        }

    }

}
